package logic

import (
	"api/models/mysql"
	"api/pkg"
	"context"

	"usersrv/internal/svc"
	"usersrv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type RealNameLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewRealNameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RealNameLogic {
	return &RealNameLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *RealNameLogic) RealName(in *user.RealNameReq) (*user.RealNameResp, error) {
	// todo: add your logic here and delete this line
	var err error
	r := mysql.RealName{}

	if !pkg.RealName(in.RealName, in.IDCard) {
		logx.Error("第三方实名认证失败")
		return nil, err
	}
	r.RealName = in.RealName
	r.IDCard = in.IDCard
	r.UserId = in.UserId
	err = r.Creates()
	if err != nil {
		logx.Error("确保实名认证信息失败")
	}
	return &user.RealNameResp{}, nil
}
